package com.atlansheng.rocketmqdemoboot.demos.consumer;

import com.alibaba.fastjson.JSON;
import com.atlansheng.rocketmqdemoboot.demos.po.OneJifen;
import com.atlansheng.rocketmqdemoboot.demos.po.OneOrder;
import com.atlansheng.rocketmqdemoboot.demos.service.JiFenService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @ClassName: OrderConsumer
 * @Description:
 * @Date 2024/03/04 17:27
 * @Author songshaoqiu
 **/
@Slf4j
@Service
@RocketMQMessageListener(topic = "transactionTopic",consumerGroup = "OrderConsumer")
public class OrderConsumer implements RocketMQListener<String> {

    @Autowired
    private JiFenService jiFenService;
    @Override
    @Transactional
    public void onMessage(String message) {
        log.info("消费消息111111,{}",message);
        OneOrder oneOrder = JSON.parseObject(message, OneOrder.class);
        OneJifen oneJifen = new OneJifen();
        oneJifen.setOrderNo(oneOrder.getOrderNo());
        oneJifen.setJiFen("400");
        oneJifen.setCreateTime(new Date());
        jiFenService.save(oneJifen);

    }
}
